package com.xms.security.service.role;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.xms.core.config.FinalValueDefaults;
import com.xms.datacore.service.UpdaterService;
import com.xms.security.entity.Roles;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;

/**
 * <p>
 * RolesUpdaterService
 * </p>
 *
 * @author migo
 * @since 2021/10/8
 */
@Service
public class RolesUpdaterService extends UpdaterService<Roles> implements IRolesUpdaterService {

    @Transactional(rollbackFor=Exception.class)
    @Override
    public boolean updateState(boolean isEnabled, List<UUID> id) {
        UpdateWrapper<Roles> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().set(Roles::getStatecode, isEnabled)
                .in(Roles::getRoleid, id).ne(Roles::getRoleid, FinalValueDefaults.ADMIN_ROLEID);
        return super.update(updateWrapper);
    }
}
